package com.kx.yooli.kx.wechat.config.flex;

import com.mybatisflex.core.audit.AuditManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

/**
 * @author john_sqwen-childe.wen
 * date 2024/5/9
 * PROJECT_NAME wechat
 * description create MyBatisFlexConfiguration by john_sqwen
 * and  value is
 */
@Configuration
public class MyBatisFlexConfiguration {
    private final Logger log = LoggerFactory.getLogger(MyBatisFlexConfiguration.class);
    public MyBatisFlexConfiguration() {
        //开启审计功能
        AuditManager.setAuditEnable(true);

        //设置 SQL 审计收集器
        AuditManager.setMessageCollector(auditMessage ->
                log.info("sql 为：{},用户查询IP为：-{},查询时间为：{}单位(ms)", auditMessage.getFullSql(),auditMessage.getHostIp()
                        , auditMessage.getElapsedTime())
        );
    }
}
